<template>
	<view class="userInfo">
		<view style="height: 20rpx;"></view>
		<tui-list-view>
			<tui-list-cell>
				<view class="cell">
					<view class="label">
						旧密码
					</view>
					<view class="val">
						<input type="text" placeholder="输入就密码" :disabled="disabled" v-model="userInfo.password">
					</view>
				</view>
			</tui-list-cell>
			<tui-list-cell>
				<view class="cell">
					<view class="label">
						新密码
					</view>
					<view class="val">
						<input type="text" placeholder="输入就密码" :disabled="disabled" v-model="userInfo.newPassword">
					</view>
				</view>
			</tui-list-cell>
			<tui-list-cell>
				<view class="cell">
					<view class="label">
						确认密码
					</view>
					<view class="val">
						<input type="text" placeholder="输入就密码" :disabled="disabled" v-model="userInfo.surePassword">
					</view>
				</view>
			</tui-list-cell>
		</tui-list-view>
		<view class="subBtns" @click="submit">保存</view>
	</view>
</template>

<script>
	const util = require("@/utils/util.js")
	const app = getApp()
	export default {
		name: '',
		components: {

		},
		props: {

		},
		data() {
			return {
				userInfo: {
					password: '',
					newPassword: '',
					surePassword: ''
				},
				disabled: false,
			};
		},
		computed: {

		},
		watch: {

		},
		onLoad() {
			
		},
		onShow() {

		},
		methods: {
			
			submit() {
				if (!this.userInfo.password) {
					return util.toast('请输入旧密码');
				}
				if (!this.userInfo.newPassword) {
					return util.toast('请输入新密码');
				}
				if (!this.userInfo.surePassword) {
					return util.toast('请输入确认密码');
				}
				if (this.userInfo.newPassword !== this.userInfo.surePassword) {
					return util.toast('请确认输入密码一致');
				}
				uni.showLoading({
					title: '提交中...'
				})
				util.request('auth/password', this.userInfo , 'POST').then(function(res) {
					uni.hideLoading();
					if (res.code == 0) {
						uni.clearStorage({
							success() {
								util.toast('修改成功,请重新登录');
								setTimeout(function() {
									uni.reLaunch({
										url: '/pages/index/index',
									})
								}, 1000)
							}
						})
					} else {
						util.toast(res.msg);
					}
				});
			}
		},
	};
</script>

<style lang="scss">
	.userInfo {
		.head {
			width: 100%;
			padding: 60rpx 0;
			background: #fff;
			text-align: center;
			.icon {
				width: 100rpx;
				height: 100rpx;
			}
			.text {
				font-size: 28rpx;
				color: #333;
				padding-top: 10rpx;
			}
		}
		
		.cell {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: flex-start;
			color: #333;
			font-size: 26rpx;
			padding: 0 30rpx 0 0;
			.label {
				width: 140rpx;
				flex-shrink: 0;
			}
			.val {
				width: 100%;
				input {
					font-size: 26rpx;
				}
				.gender {
					margin: 0 30rpx 0 20rpx;
				}
			}
		}
	}
</style>
